package org.rency.mq.kafka.consumer.support.factory;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.listener.AbstractMessageListenerContainer;
import org.springframework.kafka.listener.KafkaMessageListenerContainer;
import org.springframework.kafka.listener.config.ContainerProperties;

/**
 * 消息监听器容器工厂
 *
 * @author: Created by user_rcy@163.com on 2016/10/21.
 * @version: V1.0.0
 * @since JDK 1.8
 */
public class KafkaMessageListenerContainerFactory<K, V> implements FactoryBean<AbstractMessageListenerContainer<K, V>>{

    private ConsumerFactory<K, V> consumerFactory;

    private ContainerProperties   containerProperties;

    public KafkaMessageListenerContainerFactory(ConsumerFactory<K, V> consumerFactory,ContainerProperties containerProperties){
        this.consumerFactory = consumerFactory;
        this.containerProperties = containerProperties;
    }

    public AbstractMessageListenerContainer<K, V> getContainer(){
        return new KafkaMessageListenerContainer(this.consumerFactory,this.containerProperties);
    }

    @Override
    public AbstractMessageListenerContainer<K, V> getObject() throws Exception {
        return this.getContainer();
    }

    @Override
    public Class<?> getObjectType() {
        return KafkaMessageListenerContainer.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}